package lemmatizer;

import java.io.IOException;

import org.annolab.tt4j.TokenHandler;
import org.annolab.tt4j.TreeTaggerException;
import org.annolab.tt4j.TreeTaggerWrapper;
import static java.util.Arrays.asList;

public class Lemmatizer {
	static protected String lemmatized_word;
	static private TreeTaggerWrapper<String> tt;
	
	static {
		// Point TT4J to the TreeTagger installation directory. The executable
		// is expected
		// in the "bin" subdirectory - in this example at
		// "C:/TreeTagger/bin/tree-tagger"
		System.setProperty("treetagger.home", "C:/TreeTagger");
		tt = new TreeTaggerWrapper<String>();
		
		try {
			tt.setModel("C:/TreeTagger/lib/french.par:latin1");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		tt.setHandler(new TokenHandler<String>() {
			public void token(String token, String pos, String lemma) {
				lemmatized_word = lemma;
			}
		});
	}
	
	public static void destroy() {
		tt.destroy();
	}
	
	public static String lemme(String word) {
		try {
			tt.process(asList(word));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TreeTaggerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return lemmatized_word;
	}
}